package com.computec.core.imagenes.base.constantes;

import com.computec.core.imagenes.source.ImagenesSource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 *
 * @author Jose Luis Perea
 */

public class ConstantesGenerales {
    
    protected static ConstantesGenerales instance;
    
    public static String FACTORYDAO_CLASSNAME;
    public static String SCHEMA;
    
    public static SimpleDateFormat SIMPLE_DATE_FORMAT;
    
    public static String SCHEDULED_STATE;
    public static String EXECUTED_STATE;
    public static String REMOVED_STATE;
    public static String ALL_CICLOS;
    public static HashMap MESES; 
    public static HashMap ESTADOS; 
    
    public static int HOUR_RANGE_FROM;
    public static int HOUR_RANGE_TO;
    public static int SLEEP_TIME;
    
    public static String COPY_PATH;  
    
    public static String PATH_IMAGENES;  
    public static String PATH_BASE_DATOS;  
    public static String PATH_CONFIGURACION;  
    public static String NAME_BD_FILE; 
        
    protected ConstantesGenerales() {       
        ImagenesSource imagenesSource = ImagenesSource.getInstance();
        
        this.FACTORYDAO_CLASSNAME       = imagenesSource.getCoreImagenesSetupKey("DaoFactoryClassName");  
        this.SCHEMA                     = imagenesSource.getCoreImagenesSetupKey("schema");  
        
        this.SIMPLE_DATE_FORMAT = new SimpleDateFormat(imagenesSource.getCoreImagenesSetupKey("simpleDateFormat"));
        
        this.SCHEDULED_STATE = imagenesSource.getCoreImagenesSetupKey("ScheduledState");  
        this.EXECUTED_STATE = imagenesSource.getCoreImagenesSetupKey("ExecutedState");  
        this.REMOVED_STATE = imagenesSource.getCoreImagenesSetupKey("RemovedState"); 
        this.ALL_CICLOS = imagenesSource.getCoreImagenesSetupKey("allCiclos");
        this.MESES = this.getMesesMap();
        this.ESTADOS = this.getEstadosMap(imagenesSource.getCoreImagenesSetupKey("StatesNames"));
        
        this.HOUR_RANGE_FROM = Integer.parseInt(imagenesSource.getCoreImagenesSetupKey("HourRangeFrom"));
        this.HOUR_RANGE_TO = Integer.parseInt(imagenesSource.getCoreImagenesSetupKey("HourRangeTo"));
        this.SLEEP_TIME = Integer.parseInt(imagenesSource.getCoreImagenesSetupKey("sleepTime"));
        
        this.COPY_PATH = imagenesSource.getCoreImagenesSetupKey("copyPath");  
        
        this.PATH_IMAGENES = imagenesSource.getCoreImagenesSetupKey("PathImagenes");          
        this.PATH_BASE_DATOS = imagenesSource.getCoreImagenesSetupKey("PathBaseDatos");          
        this.PATH_CONFIGURACION = imagenesSource.getCoreImagenesSetupKey("PathConfiguracion");        
        this.NAME_BD_FILE = imagenesSource.getCoreImagenesSetupKey("NameBDFile");        
    }
    
    public static ConstantesGenerales getInstance() {
        if (instance == null) {
            instance = new ConstantesGenerales();
        }
        return instance;
    }
    
    private HashMap getMesesMap()
    {
        HashMap mesesAux = new HashMap();        
        mesesAux.put("1", "Enero");
        mesesAux.put("2", "Febrero");
        mesesAux.put("3", "Marzo");
        mesesAux.put("4", "Abril");
        mesesAux.put("5", "Mayo");
        mesesAux.put("6", "Junio");
        mesesAux.put("7", "Julio");
        mesesAux.put("8", "Agosto");
        mesesAux.put("9", "Septiembre");
        mesesAux.put("10", "Octubre");
        mesesAux.put("11", "Noviembre");
        mesesAux.put("12", "Diciembre");
        return mesesAux;
    }
    
    private HashMap getEstadosMap(String statesNames)
    {
        HashMap statesAux = new HashMap();        
        String[] estadosArray = statesNames.split(";");
        
        for(int i = 0; i < estadosArray.length; i++)
        {
            String[] infoestado = estadosArray[i].split("-");
            statesAux.put(infoestado[0], infoestado[1]);
        }        
        return statesAux;
    }
}